package com.prs.crm.action.sys;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.hibernate.criterion.DetachedCriteria;

import com.prs.crm.domain.sys.DesktopSet;
import com.prs.crm.service.sys.DesktopSetService;

public class DesktopSetAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	private DesktopSet desktopSet;
	private DesktopSetService desktopSetService;
	private Integer[] ids;
	private PaginationSupport pagination;
	public DesktopSet getDesktopSet() {
		return desktopSet;
	}
	public void setDesktopSet(DesktopSet desktopSet) {
		this.desktopSet = desktopSet;
	}
	public DesktopSetService getDesktopSetService() {
		return desktopSetService;
	}
	public void setDesktopSetService(DesktopSetService desktopSetService) {
		this.desktopSetService = desktopSetService;
	}
	public Integer[] getIds() {
		return ids;
	}
	public void setIds(Integer[] ids) {
		this.ids = ids;
	}
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	
	@Action("listDesktopSet")
	public String listDesktopSet(){
		DetachedCriteria criteria=this.getPaginationHelper().createQuery(DesktopSet.class);
		pagination =this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.getDesktopSetService().listByPage(criteria, pagination));
		return SUCCESS;
	}
	
	@Action("editDesktopSet")
	public String editDesktopSet(){
		return SUCCESS;
	}
	@Action(value="saveDesktopSet",results={
			@Result(name="success",type="redirect",location="listDesktopSet"),
			@Result(name="error",type="chain",location="editDesktopSet")
	})
	public String saveDesktopSet(){
		if (desktopSet.getModelName()==null||"".equals(desktopSet.getModelName().trim())) {
			addActionError("模板名字不能为空！");
			return ERROR;
		}
		if (desktopSet.getUrl()==null||"".equals(desktopSet.getUrl().trim())) {
			addActionError("路径不能为空！");
			return ERROR;
		}
		this.getDesktopSetService().save(desktopSet);
		return SUCCESS;
	}
	@Action(value="removeDesktopSet",results={
			@Result(name="success",type="redirect",location="listDesktopSet"),
			@Result(name="error",type="chain",location="listDesktopSet")
	})
	public String removeDesktopSet(){
		if(ids==null){
			addActionError("请选择一行进行操作！");
			return ERROR;
		}
		this.getDesktopSetService().batchRemove(ids);
		return SUCCESS;
	}
}
